var httpUrl;
var addrId;
var captchaToken;
var grouponId;

//秒杀排队
function seckill() {
    console.log('提交...');
    httpUrl = "http://t.yhd.com/tuangou/seckill.do";
    $.ajax({
        type: "POST",
        url:  httpUrl,
        dataType:'json',
        data: {
            orderInfoId:addrId,
            verifyCode:null,
            serialId:0,
            verifySig:0,
            captchaToken:captchaToken,
            buyNums:1,
            invokeType:0,
            grouponId:grouponId
        },
        success: function(responseData){
            if(responseData.code==1){ //普通秒杀下单成功
                var orderCode = responseData.data;
                var url = "http://my.yhd.com/order/finishOrder.do?orderCode="+orderCode;
                window.location=url;
            }else if(responseData.code==50){//排队秒杀排队成功
                var token = responseData.data;
                var url = "http://cart.yhd.com/cart/yqs/waiting.do?token="+token+"&returnUrl=";
                window.location=url;
            }else if(responseData.code==51){//排队秒杀排队不成功
                //alert(responseData.message);
                var url = "http://cart.yhd.com/cart/yqs/waiting.do?status=fail&code="+responseData.code;
                window.location=url;
            }else if(responseData.code==60){//排队秒杀,排队人数达到上限
                //alert(responseData.message);
                //跳到购物车
                var url = "http://cart.yhd.com/cart/yqs/waiting.do?status=fail&code="+responseData.code;
                window.location=url;
            }else if(responseData.code==61){//排队秒杀,用户购买数达到上限
                //alert(responseData.message);
                //跳到购物车
                var url = "http://cart.yhd.com/cart/yqs/waiting.do?status=fail&code="+responseData.code;
                window.location=url;
            }else{
                console.log(responseData.message);
            }
        }
    });
}

(function(){
    var curUrl = window.location.href;
    if(curUrl.indexOf("seckill") == -1){
        console.log("当前页不是秒杀页面",new Date().getTime());
        return;
    }
    var reg = /(\d+)/g;
    grouponId = curUrl.match(reg)[0];
    addrId = $('#seckillList').find('.flash_info').attr('data-receiverid');
    captchaToken = $('#__yct_str__').val();
    console.log(grouponId,addrId,captchaToken);
    seckill();
})();